#ifndef __IMAGE__H
#define __IMAGE__H

#include <cstdio>
#include <cstdlib>
#include "types.h"
#include "Rect.h"
class Image {
public:
	Image(U32 nWidth, U32 nHeight);
	
	U32 GetWidth() const { return m_nWidth; }
	U32 GetHeight() const { return m_nHeight; }
	U8 *GetData() { return m_pData; }
	const U8 *GetData() const { return m_pData; }
	void GetBoundingRect(Rect<S32> *pRect) const { pRect->SetLeftTopWidthHeight(0, 0, m_nWidth, m_nHeight); }
	void ColorSwitch(U8 nSrc, U8 nDest);
	U32 GetPix(S32 nRow, S32 nCol) const;
	void SetPix(S32 nRow, S32 nCol, U8 nColor); 
	bool Save(const char *szFileName) { return Saver::Save(this, szFileName); }
	class Loader {
	public:
		static Image *Load(const char *szFilename);
	private:
		static void SkipPGMComments(FILE *f);
		static void GoToNextLine(FILE *f);
	};
	class Saver {
	public:
		static bool Save(const Image *pImage, const char *szFileName);
	};
	friend class Loader;
	friend class Saver;
private:
	U8 *m_pData;
	S32 m_nWidth;
	S32 m_nHeight;	
};
#endif
